package tz.data;

import java.util.List;


/**
 * 
 * @author dejvid
 *
 */
public abstract class Article 
{
	public abstract String getArticleText();
	public abstract String getArticleID();
	public abstract String getArticleTopics();
	public abstract boolean hasTopics();
	public abstract Integer getNewId();

	
	public void getWordsFromArticle(List<String> lstStr)
	{
		if(lstStr != null)
		{
			String articleText = getArticleText();
			StringBuffer sb = null;
			int state = 0;
			int i = 0;
			char curC;
			while(state != -1)
			{
				switch(state)
				{
					case 0: //nextchar state
						sb = new StringBuffer();
						state =  1;
						break;
					case 1: //beremo nasledno črko
						if(i == articleText.length())
						{
							//konec!
							state = -1;
							if(sb.length() != 0)
							{
								lstStr.add(sb.toString().toLowerCase());
							}
							break;
						}
						curC = articleText.charAt(i);
						i++;
						if(isLetter(curC))
						{
							sb.append(curC);
						}
						else
						{	//ni črka, zaklučimo niz!
							if(sb.length() == 0)
							{
								state = 1;
							}
							else
							{
								lstStr.add(sb.toString().toLowerCase());
								state = 0;
							}
						}
						break;
					case 2: 
				}
			}
		}
	}
	
	private static boolean isLetter(char c)
	{
		if( c >= 'a' && c <='z' || c>= 'A' && c <= 'Z')
			return true;
		else
			return false;
	}
	
}

